<template>
  <div class="shopwrapjd" ref="shopwrapjd">
    <div class="top" ref='top' ></div>
    <div class="shoplist">
      <ul>
        <li v-for="(item,index) in optionList" 
           :key="item.cateId" 
           :class="{'current':currentIndex==index}" 
           @click="goShopList(index,item)"
           :cateId="item.cateId">
          {{item.cateName}}
        </li>
      </ul>
    </div>
    <div class="shopcontent" ref="shopcontent">
      <ul>
        <li v-for="(items,index) in shopList" 
            :key="items.cateId" 
            v-if="items.list" 
            ref="listGroup"
            > 
            <p>{{items.cateName}}</p>
            <div class="shopPic">
              <ul>
                <li v-for="item in items.list" :key="item.cateId" @click="goGoodsList(item.cateId)">
                  <div class="pic">
                     <img v-lazy="{ 
                          loading: 'http://alicdn.avicare.cn/group1/M00/01/42/O24cYVk6SI2Aab6hAAAnOPGrbVU193.jpg',
                          src: item.cateIcon,
                          error: 'http://alicdn.avicare.cn/group1/M00/00/7F/O24cYVjt4GKAJovCAABAeKv7Krs288.jpg'}" />
                    <!-- <img :src="item.cateIcon" alt=""> -->
                  </div>
                  <p>{{item.cateName}}</p>
                </li>
              </ul>
            </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      optionList: [],
      currentIndex: 0,
      cateId: "",
      shopList: [],
    };
  },

  mounted() {
    this.$nextTick(() => {
      this.getDatas();
      
    });
  },
  methods: {
    getDatas() {
      this.$axios
        .get(
          process.env.baseUrl + "/web-avicare-1.0/weixin/mall/findjdmdsecateone"
        )
        .then(res => {
          this.optionList = res.data.list;
         this.cateId=this.optionList[0].cateId
         this.getShopList();
        })
        .catch(error => {
          console.log(error);
        });
    },
    getShopList() {
      this.$axios
        .get(
          process.env.baseUrl +
            "/web-avicare-1.0/weixin/mall/findjdmdsecatepid/" +
            this.cateId
        )
        .then(res => {
          this.shopList = res.data.list;
        })
        .catch(error => {
          console.log(error);
        });
    },
    goShopList(index, item) {
      this.currentIndex = index;
      this.cateId = item.cateId;
      this.getShopList();
    },
    goGoodsList(id) {
      this.$router.push({
        name: "goodsList",
        query: { id: id, shopName: "jd_mall" }
      });
    },
    //设置列表有效高度
    // setHeight() {
    //   let top = this.$refs.top.offsetHeight;
    //   this.$refs.shopwrapjd.style.height=(window.screen.height-top)+'px' 
    //   this.$refs.shopcontent.style.height=(window.screen.height-top)+'px' 
    // }
  }
};
</script>

<style lang="less" scoped>
.shopwrapjd {
  width: 100%;
  height: auto;
  background-color: #f7f7f7;
  padding-top: 0.95rem;
  .top {
    width: 100%;
    height: 0.9rem;
    position: fixed;
    top: 0;
    left: 0;
    background: #fff;
    z-index: 99;
  }
  .shoplist {
    width: 1.8rem;
    float: left;
    position: fixed;
    top: 1rem;
    left: 0;
    bottom: 0;
    overflow-y: scroll;
    ul {
      overflow-y: scroll;
      width: 1.8rem;
      background: #ccc;
      li {
        width: 100%;
        float: left;
        font-size: 0.26rem;
        height: 1rem;
        line-height: 1rem;
        text-align: center;
        color: #232323;
        list-style: none;
        border-bottom: 1px solid #f7f7f7;
        box-sizing: border-box;
        background-color: #fff;
      }
      .current {
        background-color: #f7f7f7;
        border-left: 2px solid #78bfff;
      }
    }
  }
  .shopcontent {
    width: 5.3rem;
    float: right;
    margin-right: 0.2rem;
    position: fixed;
    top: 0.9rem;
    right: 0;
    bottom: 0;
    overflow-y: scroll;
    ul {
      overflow-y: scroll;
      width: 5.3rem;
      li {
        width: 100%;
        list-style: none;
        p {
          color: #232323;
          font-size: 0.26rem;
          text-align: left;
          font-weight: 700;
          margin-bottom: 0.09rem;
          padding-top: 0.2rem;
        }
        .shopPic {
          ul {
            width: 100%;
            padding: 0.3rem 0.3rem 0;
            overflow: hidden;
            box-sizing: border-box;
            background-color: #fff;
            li {
              list-style: none;
              width: 1.2rem;
              float: left;
              margin-right: 0.55rem;
              &:nth-child(3n) {
                margin-right: 0;
              }
              .pic {
                width: 1.2rem;
                height: 1.2rem;
                img {
                  width: 100%;
                  height: 100%;
                }
              }
              p {
                font-size: 0.26rem;
                color: #232323;
                text-align: center;
                margin-top: 0.1rem;
                margin-bottom: 0.2rem;
              }
            }
          }
        }
      }
    }
  }
}
</style>
